package com.pig4cloud.ila.client.controller;

import com.pig4cloud.ila.client.api.dto.CompilerDTO;
import com.pig4cloud.ila.client.service.CompilerService;
import com.pig4cloud.pig.common.core.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/online")
@Api(value = "online", tags = "在线做题")
public class CompilerController {

	private final CompilerService compilerService;

	@ApiOperation(value = "在线编译", notes = "在线编译")
	@PostMapping("/compiler")
	public R onlineCompiler(@RequestBody CompilerDTO compilerDTO) {
		System.out.println(compilerDTO.getCode());
		String result = compilerService.onHandleCodeFromClient(compilerDTO.getInput(), compilerDTO.getCode(), compilerDTO.getType());
		return R.ok(result);
	}
}
